//
//  imageBrowse.m
//  EFExtend
//
//  Created by mac on 15/3/12.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "imageBrowse.h"


@interface imageBrowse ()<HMUICameraDelegate>

@end

@implementation imageBrowse{
    NSMutableArray *boards;
}


- (void)dealloc
{
   
    HM_SUPER_DEALLOC();
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self.customNavLeftBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
    [self.customNavLeftBtn setFrame:CGRectMakeBound(32, 32)];
//    [HMFileCache removeAllImageCaches];
    boards = [[NSMutableArray alloc]init];
    [boards addObject:@{@"title":@"新闻滚动页",@"subtitle":@"提示、弹出",@"map":URLFOR_controller(@"news")}];
    [boards addObject:@{@"title":@"照片墙",@"subtitle":@"支持网络下载",@"map":URLFOR_controller(@"photoWall")}];
    [boards addObject:@{@"title":@"照片墙Collection",@"subtitle":@"支持网络下载",@"map":URLFOR_controller(@"CollectionWall")}];
    [boards addObject:@{@"title":@"照相",@"subtitle":@"支持网络下载",@"map":@"takePhoto"}];
    
    [self.tableView reloadData];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"rightBtn"]){//customNavRightBtn
            
        }
    }
}


#pragma  mark - table delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return boards.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier=@"listCell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (!cell) {
        cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        
    }
    NSDictionary *city = [boards objectAtIndex:indexPath.row];
    cell.textLabel.text = [city valueForKey:@"title"];
    cell.detailTextLabel.text = [city valueForKey:@"subtitle"];
    cell.detailTextLabel.textColor = RGB(.5, .5, .5);
    return cell;
}

- (void)takeController:(HMUICamera *)controller gotPhoto:(UIImage *)photo withInfo:(NSDictionary *)info{
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
    NSDictionary *city = [boards objectAtIndex:indexPath.row];
    NSString *map = [city valueForKey:@"map"];
    NSString *title = [city valueForKey:@"title"];
    
    if ([map is:@"takePhoto"]) {
        UIWindow *window = nil;
        if (![HMUIApplication sharedInstance].window) {
            window = [UIApplication sharedApplication].keyWindow;
        }else{
            window = [HMUIApplication sharedInstance].window;
        }
        UIViewController *vc = window.rootViewController;//[HMUIApplication sharedInstance].window.rootViewController;
        HMUICamera *camera = [[HMUICamera alloc]init];
        camera.viewControllerForPresentingImagePickerController = self;
        camera.delegate = self;
        camera.allowsEditingPhoto = YES;
        camera.cancelText = @"取消";
        camera.takePhotoText = @"拍照";
        [camera takePhoto];
        return;
    }
    
    UIViewController *c =[self pushToPath:map animated:YES];
    if ([c isKindOfClass:[UINavigationController class]]) {
        [(UINavigationController*)c topViewController].title = title;
    }else{
        c.title = title;
    }
}
@end
